package es.usj.apps.moviles.overlays;

import java.util.ArrayList;

import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;

public class StationOverlay extends BalloonItemizedOverlay<OverlayItem> {

	public int tag = 0;
	private ArrayList<OverlayItem> mOverlayItems = new ArrayList<OverlayItem>();

	public interface OnTouchMarkerListener {
		public void onTouchMarker(GeoPoint result);
	}

	OnTouchMarkerListener mListener = null;

	public void setOnTouchMarker(OnTouchMarkerListener listener) {
		mListener = listener;
	}

	public void clear() {
		mOverlayItems.clear();
	}

	public void doPopulate() {
		populate();
		setLastFocusedIndex(-1);
	}

	public void setTag(int tag)
	{
		this.tag = tag;
	}
	
	public int getTag()
	{
		return this.tag;
	}
	
	public StationOverlay(Drawable defaultMarker, MapView mapView) {

		super(boundCenterBottom(defaultMarker), mapView);
	}

	public void addOverlayItem(OverlayItem item) {
		mOverlayItems.add(item);
		//doPopulate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlayItems.get(i);
	}

	@Override
	public int size() {
		return mOverlayItems.size();
	}

	
	@Override
	protected boolean onBalloonTap(int index, OverlayItem item) {
		
		//return super.onBalloonTap(index, item);
		
		if (mListener != null) {
			mListener.onTouchMarker(mOverlayItems.get(index).getPoint());
		}

		return true;
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {

		super.draw(canvas, mapView, shadow);
	}
}
